package com.miracle9.game.dao;
import com.miracle9.game.entity.Busine;
import com.miracle9.game.util.MyUtil;
import java.util.Date;
import java.util.List;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

@Repository
public class BusineServiceDao extends SqlOperating<Busine, Integer>
{
  public Busine getAndSave()
  {
    Busine busine = (Busine)q_CreateSqlFilter("from Busine order by id desc limit 1", new Object[0]);
    if (busine == null)
    {
      busine = new Busine();
      busine.setStartDate(MyUtil.dateFormatYMD_HMS_Sting(new Date()));
      busine.setEndDate(MyUtil.dateFormatYMD_HMS_Sting(new Date()));
      busine.setStatus(2);
      busine.setShiftWorkType(0);
      busine.setCurrentShiftType(0);
      save(busine);
    }
    return busine;
  }
  
  public List<Object[]> getListBydate(String date)
  {
    Query query = q_CreateSql(
      "select id,shiftWorkType,(select sum(payCount)-sum(exchangeCount)+sum(takeDeposit)-sum(returnDeposit) from BusineInfo where busineId = b.id),startDate,endDate from Busine b where status=2 and startDate like ? order by endDate asc", new Object[] {
      date + "%" });
    return query.list();
  }
}
